<template>
  <div id="time-line">
    <div class="common-detail">
      <div class="info-title">{{title}}</div>
      <div class="time-line">
        <a-timeline>
          <a-timeline-item :color="(item.rproposalAuditRecordList.length > 0 || item.status) ? 'blue' : 'gray'" v-for="(item, index) in list" :key="index">
            <p>{{item.role_name}}</p>
            <div class="flex" v-if="item.rproposalAuditRecordList.length">
              <div class="time-line-name">{{item.rproposalAuditRecordList[0].auditMan}}</div>
              <!-- item.status是true的时候代表到这个角色审批 -->
              <div class="time-line-right" v-if="!item.status">
                <div class="flex">
                  <div class="time-line-status" :class="statusClass(item)">{{enumStatus(item.rproposalAuditRecordList[0].state)}}</div>
                  <div class="time-line-date">{{item.rproposalAuditRecordList[0].auditTime}}</div>
                </div>
                <div class="time-line-remark" v-if="item.rproposalAuditRecordList[0].remark">审批说明： {{item.rproposalAuditRecordList[0].remark}}</div>
              </div>
            </div>
            <!-- 审核 -->
            <div class="audit" v-if="item.status && !readOnly">
              <a-radio-group v-model="form.auditStatus">
                <a-radio :value="1"> 审批通过 </a-radio>
                <a-radio :value="2"> 审核不通过 </a-radio>
              </a-radio-group>
              <div class="flex">
                <div class="input-box">
                  <a-textarea autoSize v-model="form.remark" placeholder="审批备注" />
                </div>
                <a-button type="primary" @click="handleConfirm">确定</a-button>
              </div>
            </div>
          </a-timeline-item>
        </a-timeline>
      </div>
    </div>
  </div>
</template>
<script lang='ts'>
import { Component, Watch, Vue, Prop } from 'vue-property-decorator';
enum StatusMap {
  '已提交' = 1,
  '已同意' = 2,
  '不通过' = 3
}
@Component
export default class timeLine extends Vue {
  @Prop({type: Array, default: () => []}) list!: any
  @Prop({type: String, default: '审批进度'}) title!: string
  @Prop({type: Boolean, default: false}) readOnly!: boolean

  form: any = {
    auditStatus: '',
    remark: ''
  }
  statusClass (item: any): string {
    return item.rproposalAuditRecordList[0].state === 3 ? 'red' : 'blue'
  }
  enumStatus (status: number): string {
    return StatusMap[status]
  }
  handleConfirm () {
    if (this.form.auditStatus === '') return this.$message.error('请勾选审批意见')
    if (this.form.auditStatus === 2 && !this.form.remark.trim().length) return this.$message.error('请填写审核不通过备注')
    this.$emit('confirm', this.form)
  }
}
</script>
<style lang='scss' scoped>
#time-line {
  .flex {
    display: flex;
    align-items: center;
  }
  .time-line {
    .time-line-name {
      font-weight: 600;
    }
    .time-line-right {
      margin-left: 50px;
      .time-line-status {
        margin-right: 20px;
        &.blue{
          color: #0091fa;
        }
        &.red{
          color: #ff2332;
        }
      }
    }
    .audit {
      margin-top: 10px;
      .input-box {
        width: 300px;
        margin-right: 20px;
      }
      .flex {
        margin-top: 10px;
      }
    }
  }
}
</style>
